<template>
  <div id="tab-control">
    <div v-for="(item, index) in titles"
         :key="index" class="tab-control-item"
         :class="{active:currentIndex === index }"
         @click="btnClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  import pubsub from 'pubsub-js'

  export default {
    name: "TabControl",
    props:{
      titles:{
        type:Array,
        default(){
          return []
        }
      }
    },
    data(){
      return{
        currentIndex:0,
      }
    },
    methods:{
      btnClick(index){
        this.currentIndex = index
        this.$emit('tabClick', index)
        pubsub.publish('tabClick', index)
      }
    },
  }
</script>

<style scoped>
  #tab-control{
    display: flex;
    text-align: center;
    font-size: 14px;
    line-height: 44px;
    height: 44px;
  }
  .tab-control-item{
    flex: 1;
  }
  .active span{
    padding: 5px;
    color: #50b7c1;
    border-bottom: 3px solid #50b7c1;
  }

</style>